<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;
$this->title = '问答管理';
?>
<div class="container">
    <div class="row">
      
        <?php echo $this->render('_leftnav') ?>

        <div class="col-md-10">
          <div class="page-header clearfix">
            <h1 class="pull-left">问答管理</h1>
            <div class="pull-right">

                                            
            </div>
          </div>

<div class="btn-group">
<a href="<?= Url::to(['course/classques'])?>&ques_type=0" type="button" class="btn btn-default btn-sm dianji" >课程问答</a>

<a href="<?= Url::to(['course/classques'])?>&ques_type=1" type="button" class="btn btn-default btn-sm btn-primary dianji1">有问必答</a>
</div><br>

  <div class="well well-sm mtl">
  <form class="form-inline" action="index.php?r=course/classsel" method="post">
      <div class="form-group">
        <select class="form-control sel_condition" name="condition">
          <option selected="selected" value="title">标题</option>
   		  <option value="content">内容</option>
        </select>
      </div>
      <div class="form-group">
        <input class="form-control" name="keywords" placeholder="关键词" type="text" value="<?php if(isset($keyword)) echo $keyword?>">
      </div>
      <span class="divider"></span>
   
      <div class="form-group">
        <input class="form-control" placeholder="作者" type="text" name="author" value="<?php if(isset($author)) echo $author?>">
      </div>
   	  <input type="hidden" value="1" name="hidd">
      <input class="" type="submit" value="搜索">
    </form>
  </div>

  <div id="question-table-container">
    <table id="question-table" class="table table-striped table-hover">
      <thead>
        <tr>
          <th width="5%"></th>
          <th width="50%">问答</th>
                      <th width="10%">回复\查看</th>
                    <th width="10%">作者</th>
          <th width="10%">创建时间</th>
          <th width="15%">操作</th>
        </tr>
      </thead>
      <tbody class="tbody">
                <?php 
					foreach($name as $key=>$val){
				?>
				
                                        <tr data-role="item">
            <td><input data-role="batch-item" type="checkbox" name="xuan[]" value="<?php echo $val['ques_id'];?>"> </td>
            <td>
              <a href="#" target="_blank"><strong><?= Html::encode($val['ques_name']);?></strong></a>

              <div class="short-long-text">
<div class="short-text text-sm text-muted <?php echo 'a'.$val['ques_id']?>" style="display:block" id="<?php echo 'a'.$val['ques_id']?>"><?= Html::encode(substr($val['ques_content'],0,60))?>...<span class="trigger open_up" id="<?php echo $val['ques_id']?>">(展开)</span></div>


                <div class="long-text <?php echo $val['ques_id']?>" style="display:none" ><p><span style="color:rgb(102,102,102);"><?= Html::encode($val['ques_content'])?></span></p> <span class="trigger close_up" copy_zhi=<?php echo 'a'.$val['ques_id']?> off="<?php echo $val['ques_id']?>">(收起)</span></div>
              </div>
            
     <!--          <div class="text-sm mts">
                                  <a href="#" class="text-success" target="_blank">
              								 123123
              								  </a>
                                                </div> -->
            </td>
            <td>
            <span class="text-sm"><?= Html::encode($val['ques_answersum'])?>\<?= Html::encode($val['ques_viewsum'])?></span>
            </td>
            <td><a href="javascript:;" role="show-user" data-toggle="modal" data-target="#modal" data-url="http://dcoffee.edusoho.com.cn/admin/user/1"><?= Html::encode($val['user_name'])?></a>
	 <br>
            </td>
            <td>
              <?= Html::encode(date("Y-m-d H:i:s",$val['ques_addtime']))?>
            </td>
            <td>
            

      <div class="btn-group">
<!--         <a class="btn btn-default btn-sm remind-teachers" title="提醒教师" data-url="/admin/course/1/question/6/remindTeachers" <span="">提醒教师
        </a> -->
        <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
          <span class="caret"></span>
        </a>
        <ul class="dropdown-menu pull-right">
          <li>
            <a class="btn delanswer" data-role="item-delete" data-name="删除问答" data-url="/admin/thread/6/delete" name="<?php echo $val['ques_id']?>">
              <span class="glyphicon glyphicon-trash"></span>删除问答</a>
          </li>
        </ul>

      </div>

            </td>
          </tr>
		  <?php
  }
			?>
              </tbody>
    </table>
	<?php echo LinkPager::widget([
				'pagination' => $pagination,
				'prevPageLabel'=>'上一页',
				'nextPageLabel'=>'下一页',
			]);?>

    <div class="mbm">
        <label class="checkbox-inline"><input data-role="batch-select" type="checkbox" class="check_ze" id="all_xuan"> 全选</label>
        <button class="btn btn-default btn-sm mlm" data-role="batch-delete" data-name="问答" data-url="/admin/thread/batch_delete" id="del">删除</button>
    </div>
  </div>
    
    
        </div>

          </div>
  </div>



  <script>
//点击展开
	$(".open_up").click(function(){
	var id=$(this).attr("id");
	var aid=$(this).parent().attr("id");
	$("."+id).css("display","block");
	$("."+aid).css("display","none");
	})

//点击收起
$(".close_up").click(function(){
	var id=$(this).attr("copy_zhi");
	var off=$(this).attr("off");
	$("."+off).css("display","none");
	$("."+id).css("display","block");
})

//全选
	
	$(".check_ze").click(function(){
		var id = document.getElementById("all_xuan");
		var name = document.getElementsByName("xuan[]");
	if(id.checked==true){
		for(i in name){
			if(name[i].checked==false){
				name[i].checked=true;
			}
		}
	}else{
		for(i in name){
			if(name[i].checked==true){
				name[i].checked=false;
			}
		}
	}
	})
//批量删除
$("#del").click(function(){
	var xuan = document.getElementsByName('xuan[]');
	var str='';
	for(i in xuan){
		if(xuan[i].checked==true){
			str+=xuan[i].value+',';
		}
	}
	if(str==''){
		alert("您未选择要删除的记录!!");
	} 
	if(confirm("您确定要删除这条记录?")){
	$.ajax({
   type: "POST",
   url: "index.php?r=course/classdel",
   data: "id="+str,
   success: function(msg){
     alert("删除成功!")
	 location.reload();
   }
})
}
})
//删除问答（单个）
$(".delanswer").click(function(){
	var zhi = $(this).attr("name");
	if(confirm("您确定要删除这条记录?")){
	$.ajax({
   type: "POST",
   url: "index.php?r=course/classdel",
   data: "id="+zhi,
   success: function(msg){
     alert("删除成功!")
	 location.reload();
   }
})
}
})
</script>